using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace TimeCameraServer.Controllers
{
  public class FailureController : ControllerBase
  {
    protected async ValueTask<IActionResult> FailureProcess(Func<ValueTask<IActionResult>> success)
    {
      try
      {
        return await success();
      }
      catch (ArgumentException e)
      {
        return BadRequest(e.Message);
      }
      catch (InvalidOperationException e)
      {
        return Unauthorized(e.Message);
      }
    }
  }
}
